// ==UserScript==
// @name     Invidious Settings
// @version  1
// @grant    GM_cookie
// @run-at   document-start
// @include  https://yewtu.be/*
// @include  https://vid.puffyan.us/*
// @include  https://inv.riverside.rocks/*
// @include  https://invidious.kavin.rocks/*
// @include  https://invidio.xamh.de/*
// @include  https://y.com.sb/*
// @include  https://invidious.nerdvpn.de/*
// @include  https://yt.artemislena.eu/*
// @include  https://invidious.tiekoetter.com/*
// @include  https://invidious.flokinet.to/*
// @include  https://inv.bp.projectsegfau.lt/*
// @include  https://inv.vern.cc/*
// @include  https://inv.odyssey346.dev/*
// @include  https://invidious.snopyta.org/*
// @include  https://invidious.baczek.me/*
// @include  https://invidious.sethforprivacy.com/*
// @include  https://yt.funami.tech/*
// @include  https://invidious.drivet.xyz/*
// @include  https://vid.priv.au/*
// @include  https://invidious.silur.me/*
// @include  https://invidious.epicsite.xyz/*
// @include  https://invidious.slipfox.xyz/*
// @include  https://iv.ggtyler.dev/*
// @include  https://invidious.dhusch.de/*
// @include  https://invidious.weblibre.org/*
// @include  https://invidious.esmailelbob.xyz/*
// @include  https://iv.melmac.space/*
// @include  https://invidious.privacydev.net/*
// @include  https://invidious.lidarshield.cloud/*
// @include  https://invidious.namazso.eu/*
// ==/UserScript==


const options = {
  "annotations"                : false,
  "annotations_subscribed"     : false,
  "autoplay"                   : true,
  "automatic_instance_redirect": false,
  "continue"                   : true,
  "continue_autoplay"          : true,
  "dark_mode"                  : "dark",
  "latest_only"                : false,
  "listen"                     : false,
  "local"                      : true,
  "watch_history"              : false,
  "vr_mode"                    : true,
  "show_nick"                  : false,
  "locale"                     : "en-US",
  "region"                     : "US",
  "max_results"                : 40,
  "notifications_only"         : false,
  "player_style"               : "invidious",
  "quality"                    : "hd720",
  "quality_dash"               : "auto",
  "default_home"               : "Popular",
  "related_videos"             : true,
  "sort"                       : "published",
  "speed"                      : 1.0,
  "thin_mode"                  : false,
  "unseen_only"                : false,
  "video_loop"                 : false,
  "extend_desc"                : false,
  "volume"                     : 100,
  "save_player_pos"            : false
}


function getPrefs() {
  for (cookie of document.cookie.split('; ')) {
    const [name, value] = cookie.split("=");
    if (name === "PREFS") {
      return JSON.parse(decodeURIComponent(value));
    }
  }
  return {};
}


let prefs   = getPrefs();
let changed = false;
for (opt in options) {
  if (prefs[opt] !== options[opt]) {
    prefs[opt] = options[opt];
    changed = true;
  }
}

if (changed === true) {
  document.cookie = "PREFS=" + encodeURIComponent(JSON.stringify(prefs)) + ";";
}
